<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/18 0018
 * Time: 14:44
 */
namespace Api\Controller;

class AdvertiListController extends CommonController
{
    //获取广告信息
    public function AdvertiList1(){
        $name = '轮播图';
        $id = M('adverti_class')->where(array('class_name'=>$name,'state'=>1))->field('adverti_class_id')->find();

        $data = M('adverti_list')->where(array('adverti_class_id'=>$id['adverti_class_id'],'state'=>1))->order('sort desc')->field('adverti_id,image,describe,url')->select();


        if(!$data){
            $this->ajaxReturn(array('code' => 201, 'msg' =>'广告获取失败' ),'json');
        }
       
        $this->ajaxReturn($data,'json');
    }

//广告位2，取3
    public function AdvertiList2()
    {
        $name = '栏目1';
        $id = M('adverti_class')->where(array('class_name' => $name,'state'=>1))->field('adverti_class_id')->find();
        $data = M('adverti_list')->where(array('adverti_class_id' => $id['adverti_class_id'],'state'=>1))->order('sort desc')->limit(4)->field('adverti_id,image,describe,url')->select();
        if (!$data) {
            $this->ajaxReturn(array('code' => 201, 'msg' => '广告获取失败'), 'json');
        }

        $this->ajaxReturn($data, 'json');
    }

    //广告位3，
    public function AdvertiList3()
    {
        $name = '栏目2';
        $id = M('adverti_class')->where(array('class_name' => $name,'state'=>1))->field('adverti_class_id')->find();
        $num = M('adverti_list')->where(array('adverti_class_id' => $id['adverti_class_id'],'state'=>1))->limit(8)->field('adverti_id,image,describe,url')->count();
        $num2 = $num / 2;
        $data1 = M('adverti_list')->where(array('adverti_class_id' => $id['adverti_class_id'],'state'=>1))->field('adverti_id,image,describe,url')
            ->order('sort desc')
            ->limit(0, $num2)
            ->select();

        //dump($data1);die;
      /*  foreach($data1 as $k=>$v){
            $data1[$k]['describe'] = (array)json_decode($v['describe']);
        }*/
//        dump($data1);die;
        $data2 = M('adverti_list')->where(array('adverti_class_id' => $id['adverti_class_id'],'state'=>1))->field('adverti_id,image,describe,url')
            ->order('sort desc')
            ->limit($num2, $num)
            ->select();

    /*    foreach($data2 as $k=>$v){
            $data2[$k]['describe'] = (array)json_decode($v['describe']);
        }*/

        if (!$data1) {
            $this->ajaxReturn(array('code' => 201, 'msg' => '广告获取失败'), 'json');
        }
        if (!$data2) {
            $this->ajaxReturn(array('code' => 201, 'msg' => '广告获取失败'), 'json');
        }

        //dump(array($data1,$data2),'json');die;
        $this->ajaxReturn(array($data1, $data2), 'json');
    }
//广告位4，
   public function AdvertiList4()
   {
       $name = '栏目3';
       $id = M('adverti_class')->where(array('class_name' => $name,'state'=>1))->field('adverti_class_id')->find();
       $data = M('adverti_list')->where(array('adverti_class_id' => $id['adverti_class_id'],'state'=>1))
           ->field('adverti_id,image,describe,url')->order('sort desc')->limit(13)->select();
       if (!$data) {
           $this->ajaxReturn(array('code' => 201, 'msg' => '广告获取失败'), 'json');
       }

       $this->ajaxReturn($data, 'json');
   }

//广告位5，
	public function AdvertiList5()
       {
           $name = '栏目4';
           $id = M('adverti_class')->where(array('class_name' => $name,'state'=>1))->field('adverti_class_id')->find();
           $data = M('adverti_list')->where(array('adverti_class_id' => $id['adverti_class_id'],'state'=>1))
               ->field('adverti_id,image,describe,url')
               ->order('sort desc')
               ->limit(10)
               ->select();
           if (!$data) {
               $this->ajaxReturn(array('code' => 201, 'msg' => '广告获取失败'), 'json');
           }

           $this->ajaxReturn($data, 'json');
       }

    //广告位6，
	public function AdvertiList6(){
        $name = '栏目8';
        $id = M('adverti_class')->where(array('class_name' => $name,'state'=>1))->field('adverti_class_id')->find();
        $data = M('adverti_list')->where(array('adverti_class_id' => $id['adverti_class_id'],'state'=>1))->order('sort desc')
            ->field('adverti_id,image,describe,url')->order('sort desc')->limit(6)->select();
        if (!$data) {
            $this->ajaxReturn(array('code' => 201, 'msg' => '广告获取失败'), 'json');
        }

        $this->ajaxReturn($data, 'json');
    }

//广告位7，
	public function AdvertiList7(){
        $name = '栏目6';
        $id = M('adverti_class')->where(array('class_name' => $name,'state'=>1))->field('adverti_class_id')->find();
        $data = M('adverti_list')->where(array('adverti_class_id' => $id['adverti_class_id'],'state'=>1))
            ->field('adverti_id,image,describe,url')->order('sort desc')->limit(8)->select();
        if (!$data) {
            $this->ajaxReturn(array('code' => 201, 'msg' => '广告获取失败'), 'json');
        }

        $this->ajaxReturn($data, 'json');
    }


    //广告位8，
    public function AdvertiList8(){
        $name = '栏目7';
        $id = M('adverti_class')->where(array('class_name' => $name,'state'=>1))->field('adverti_class_id')->find();
        $data = M('adverti_list')->where(array('adverti_class_id' => $id['adverti_class_id'],'state'=>1))
            ->field('adverti_id,image,describe,url')->order('sort desc')->limit(8)->select();
        if (!$data) {
            $this->ajaxReturn(array('code' => 201, 'msg' => '广告获取失败'), 'json');
        }

        $this->ajaxReturn($data, 'json');
    }

    //广告位9，
    public function AdvertiList9(){
        $name = '栏目5';
        $id = M('adverti_class')->where(array('class_name' => $name,'state'=>1))->field('adverti_class_id')->limit(8)->find();
        $data = M('adverti_list')->where(array('adverti_class_id' => $id['adverti_class_id'],'state'=>1))
            ->field('adverti_id,image,describe,url')->order('sort desc')->limit(8)
            ->select();
        if (!$data) {
            $this->ajaxReturn(array('code' => 201, 'msg' => '广告获取失败'), 'json');
        }

        $this->ajaxReturn($data, 'json');
    }


}